/**
 * Created by zhoumingrui on 2016/11/14.
 */
import Vue from 'vue'
import {URL_BAOTOU_HEATPOINT_ROOT} from '../global'
import {URL_BAOTOU_WEATHER} from '../global'
var vue = new Vue();

export default {
    getHotSpot (cb) {
        vue.$http.get(URL_BAOTOU_HEATPOINT_ROOT).then((response) => {
            cb(eval(response.data));
        }, (response) => {
            console.log(response.json());
        });
    },

    parseWeatherData(weatherJson){
        var weatherFormat = {}
        weatherJson.forEach(function (weatherData) {
            var key = weatherData.name_zh + weatherData.utc
            weatherFormat[key] = weatherData
        })
        return weatherFormat
    },

    getWeatherForecast(callback){
        var that = this
        var date = new Date().toString()
        vue.$http.get(`${URL_BAOTOU_WEATHER}?${date}`).then((response) => {
            var weatherFormat = that.parseWeatherData(eval(response.data.data));
            console.log("<<<<-----getWeatherForecast------<<<<<<");
            console.log(eval(weatherFormat));
            callback(weatherFormat)
        }, (response) => {
            console.log(response.json());
        });
    },
}
